<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('结项审核申请新增')"/>
</head>
<body class="pear-container" onload="start()">
<form class="layui-form" th:object="${FinishProject}">
    <h4 align="center" style="font-size: large">项目基本信息</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form-item layui-hide">
                <label class="layui-form-label">id</label>
                <div class="layui-input-block">
                    <input readonly  id="proId" type="text" th:value="*{id}" name="id" lay-verify="title"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
<!--            <label class="layui-form-label">请选择项目</label>-->
<!--            <div class="layui-input-inline" th:each="applyProject,applyProjectStat:${applyProjectList}">-->
<!--                <input readonly  type="radio" lay-filter="applyProjectList" id="applyProjectList" name="applyProjectList"-->
<!--                       th:value="${applyProject.id}" th:title="${applyProject.proName}">-->
<!--&lt;!&ndash;                <input readonly  type="text" id="applyProjectStat" class="layui-hide" th:value="${applyProjectStat.index}">&ndash;&gt;-->
<!--            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label">项目批准号</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{proNumber}" type="text" name="proNumber" autocomplete="off" placeholder="项目批准号" class="layui-input">
                </div>
                <label class="layui-form-label">承担单位</label>
                <div class="layui-input-inline">
                    <input readonly th:value="${TsysUser.deptName}" type="text" name="proDept" autocomplete="off"
                           placeholder="承担单位" class="layui-input">
                </div>

                <label class="layui-form-label">项目类型</label>
                <div class="layui-input-inline">
                    <select id="proType" lay-filter="firstProType">
                        <option value="" selected>请选择项目类型</option>
                        <option disabled th:field="*{proType}" th:checked="*{proType} eq 'a'"  value="a">新型智库项目</option>
                        <option disabled  th:field="*{proType}" th:checked="*{proType} eq 'b'"  value="b">省级社科联项目</option>
                    </select>
                </div>

                <div class="layui-input-inline" name="selectChild" id="selectChild" lay-filter="selectChild">
                    <select id="shengType">
                        <option value="" selected>请选择省级子项目类型</option>
                        <option disabled th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq 'c'" value="c">重大项目</option>
                        <option disabled th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq 'd'" value="d">一般项目</option>
                        <option disabled th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq 'e'" value="e">青年项目</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div>
                    <label class="layui-form-label">项目名称</label>
                </div>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{proName}" type="text" id="proName" name="proName" autocomplete="off" placeholder="项目名称" class="layui-input">
                </div>

                <div id="proSubject3">
                    <label class="layui-form-label">学科分类</label>
                    <div class="layui-input-inline">
                        <select id="proSubject">
                            <option value="" selected>请选择学科分类</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'a'" value="a">马列社科</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'b'" value="b">党史党建</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'c'" value="c">哲学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'd'" value="d">理论经济</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'e'" value="e">应用经济</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'f'" value="f">统计学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'g'" value="g">政治学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'h'" value="h">法学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'i'" value="i">社会学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'j'" value="j">民族学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'k'" value="k">中国历史</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'l'" value="l">世界历史</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'm'" value="m">宗教学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'n'" value="n">中国文学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'o'" value="o">外国文学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'p'" value="p">语言学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'q'" value="q">新闻学与传播学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'r'" value="r">图书馆、情报与文献学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 's'" value="s">体育学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 't'" value="t">管理学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'u'" value="u">人口学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'v'" value="v">国际问题研究</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'w'" value="w">考古学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'x'" value="x">教育学</option>
                            <option th:field="*{proSubject}" disabled   th:checked="*{proSubject} eq 'y'" value="y">艺术学</option>
                        </select>
                    </div>
                </div>

                <label class="layui-form-label">主题词</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{proWords}" style="width: 250px" type="text" name="proWords" autocomplete="off" placeholder="多个主题词以，分隔"
                           class="layui-input">
                </div>

            </div>


            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">预期成果形式</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{planType}" type="text" name="planType" autocomplete="off" placeholder="预期成果形式" class="layui-input">
                </div>

                <label class="layui-form-label" style="width: 100px">最终成果形式</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{actualType}"  type="text" name="actualType" autocomplete="off" placeholder="最终成果形式" class="layui-input">
                </div>

                <label class="layui-form-label">结项种类</label>
                <div class="layui-input-inline">
                    <select  id="finishType" name="finishType">
                        <option disabled th:field="*{finishType}" th:checked="*{finishType} eq '0'" value="0">正常</option>
                        <option disabled th:field="*{finishType}" th:checked="*{finishType} eq '1'" value="1">提前</option>
                        <option disabled th:field="*{finishType}" th:checked="*{finishType} eq '2'" value="2">延期</option>
                        <option disabled th:field="*{finishType}" th:checked="*{finishType} eq '3'" value="3">免于鉴定</option>
                        <option disabled th:field="*{finishType}" th:checked="*{finishType} eq '4'" value="4">申请中止或撤销</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">计划完成时间</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{planDate}"  type="text" id="planDate" name="planDate" autocomplete="off" placeholder="计划完成时间"
                           class="layui-input datetime-input">
                </div>

                <label class="layui-form-label" style="width: 100px">实际完成时间</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{finishDate}"  type="text" name="finishDate" autocomplete="off" placeholder="实际完成时间"
                           class="layui-input datetime-input">
                </div>

                <label class="layui-form-label" style="width: 100px">申请鉴定时间</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{applyDate}"  type="text" name="applyDate" autocomplete="off" placeholder="申请鉴定时间"
                           class="layui-input datetime-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">成果形态</label>
                <div class="layui-input-inline">
                    <select  id="resType" name="resType">
                        <option disabled th:field="*{resType}" th:checked="*{resType} eq '0'" value="0">出版物</option>
                        <option disabled th:field="*{resType}" th:checked="*{resType} eq '1'" value="1">打印稿</option>
                        <option disabled th:field="*{resType}" th:checked="*{resType} eq '2'" value="2">手稿或其他复印件</option>
                        <option disabled th:field="*{resType}" th:checked="*{resType} eq '3'" value="3">其它</option>
                    </select>
                </div>

                <label class="layui-form-label" style="width: 100px">成果字数(千)</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{resWords}"  type="text" name="resWords" autocomplete="off" placeholder="成果字数(千)" class="layui-input">
                </div>

                <label class="layui-form-label" style="width: 100px">报送成果套数</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{resQuantity}"  type="text" name="resQuantity" autocomplete="off" placeholder="报送成果套数" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">是否计划出版</label>
                <div class="layui-input-inline">
                    <input disabled  th:field="*{publishIf}" th:checked="*{publishIf} eq '0'" value="0" title="不出版" type="radio" name="publishIf"  class="layui-input">
                    <input disabled   th:field="*{publishIf}" th:checked="*{publishIf} eq '1'" value="1" title="出版"   type="radio" name="publishIf"  class="layui-input">
                </div>

                <label class="layui-form-label" style="width: 100px">出版时间和单位</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{publishDetail}" style="width: 600px" type="text" name="publishDetail" autocomplete="off" placeholder="出版时间和单位" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">获奖情况</label>
                <div class="layui-input-block">
                    <input readonly  th:value="*{proReward}" type="text" name="proReward" autocomplete="off" placeholder="获奖情况" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">转摘、引用情况</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{proUsage}" style="width: 1100px" type="text" name="proUsage" autocomplete="off" placeholder="转摘、引用情况" class="layui-input">

                </div>
            </div>
        </div>
    </div>

    <h4 align="center" style="font-size: large">项目负责人基本信息</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manName}" type="text" name="manName" autocomplete="off" placeholder="姓名" class="layui-input">
                </div>

                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input disabled  th:field="*{manSex}" th:checked="*{manSex} eq '0'" type="radio" name="manSex" value="0" title="男">
                    <input disabled  th:field="*{manSex}" th:checked="*{manSex} eq '1'" type="radio" name="manSex" value="1" title="女">
                </div>

                <label class="layui-form-label">民族</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manNation}" type="text" name="manNation" autocomplete="off" placeholder="民族" class="layui-input">
                </div>

                <label class="layui-form-label">出生日期</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manBirth}" type="text" name="manBirth" autocomplete="off" placeholder="出生日期" class="layui-input datetime-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">所在单位</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manDept}" type="text" name="manDept" autocomplete="off" placeholder="所在单位" class="layui-input">
                </div>

                <label class="layui-form-label">行政职务</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manOffice}" type="text" name="manOffice" autocomplete="off" placeholder="行政职务" class="layui-input">
                </div>

                <label class="layui-form-label">专业职称</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manTitle}" type="text" name="manTitle" autocomplete="off" placeholder="专业职务" class="layui-input">
                </div>

                <label class="layui-form-label">研究专长</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manExpertise}" type="text" name="manExpertise" autocomplete="off" placeholder="研究专长" class="layui-input">

                </div>

            </div>

            <div class="layui-form-item">

                <label class="layui-form-label">学历</label>
                <div class="layui-input-inline">
                    <select  id="manEducation" name="manEducation">
                        <option selected >请选择学历</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'g'" value="g">博士研究生</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'f'" value="f">硕士研究生</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'e'" value="e">本科</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'd'" value="d">大专</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'c'" value="c">高中</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'b'" value="b">初中</option>
                        <option disabled th:field="*{manEducation}" th:checked="*{manEducation} eq 'a'" value="a">小学</option>
                    </select>
                </div>

                <label class="layui-form-label">学位</label>
                <div class="layui-input-inline">
                    <select  id="manDegree" name="manDegree">
                        <option selected >请选择学位</option>
                        <option disabled th:field="*{manDegree}" th:checked="*{manDegree} eq 'c'" value="c">博士</option>
                        <option disabled th:field="*{manDegree}" th:checked="*{manDegree} eq 'b'" value="b">硕士</option>
                        <option disabled th:field="*{manDegree}" th:checked="*{manDegree} eq 'a'" value="a">学士</option>
                    </select>
                </div>

                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manPhone}" type="text" name="manPhone" autocomplete="off" placeholder="联系电话" class="layui-input">
                </div>

                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manEmail}" type="text" name="manEmail" autocomplete="off" placeholder="邮箱" class="layui-input">                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">邮政编码</label>
                <div class="layui-input-inline">
                    <input readonly  th:value="*{manZip}" type="text" name="manZip" autocomplete="off" placeholder="邮政编码" class="layui-input">
                </div>

                <label class="layui-form-label">通讯地址</label>
                <div class="layui-input-inline">
                    <input readonly style="width: 500px" th:value="*{manAddress}" type="text" name="manAddress" autocomplete="off" placeholder="通讯地址" class="layui-input">
                </div>
            </div>

        </div>
    </div>

    <h4 align="center" style="font-size: large">课题主要参与者基本情况</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">

            <table id="applyParticipator-table" lay-filter="applyParticipator-table"></table>

        </div>
    </div>

    <h4 align="center" style="font-size: large">课题组的主要阶段性成果</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">

            <table id="finishSatgeResult-table" lay-filter="finishSatgeResult-table"></table>

        </div>
    </div>

    <h4 align="center" style="font-size: large">总结报告</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <div class="layui-upload" align="center">
                    <input readonly   class="layui-btn" style="display: none;width: 350px" id="summaryDisplay" >
                    <input readonly   th:value="*{summaryReportUrl}" class="layui-input-inline layui-hide" style="display: none" id="uploadSummary" >
                    <button id="sum-view" type="button" class="layui-btn">文件查看</button>
                </div>
            </div>

        </div>
    </div>



    <h4 align="center" style="font-size: large">项目最终成果简介</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">

            <div class="layui-form-item">
                <div class="layui-upload" align="center">
                    <input readonly  class="layui-btn" style="display: none;width: 350px" id="tt" >
                    <input readonly  class="layui-btn" th:value="*{resContentUrl}" style="display: none" id="proResUpload" >
                    <button id="proRes-view" type="button" class="layui-btn">文件查看</button>
                </div>
            </div>


        </div>
    </div>

    <h4 align="center" style="font-size: large">查重报告</h4><br>
    <div class="layui-card">
        <div class="layui-card-body">

            <div class="layui-form-item">
                <div class="layui-upload" align="center">
                    <input readonly  class="layui-btn" style="display: none;width: 350px" id="dupDisplay">
                    <input readonly  class="layui-btn" th:value="*{dupilicateUrl}" style="display: none" id="dupUpload" >
                    <button id="dup-view" type="button" class="layui-btn">文件查看</button>
                </div>
            </div>

        </div>
    </div>
    <br><br><br>
    <br><br><br>





    <div class="layui-form-item layui-hide">
        <div class="layui-input-block">
            <input readonly  type="text" id="proIndex" class="layui-input">
        </div>
    </div>

    <div class="layui-input-block layui-hide">
        <input readonly  th:value="*{applyId}" type="text" id="applyId" name="applyId"  class="layui-input">
    </div>

    <div class="layui-input-block layui-hide">
        <input readonly id="checkProcess" th:value="${CheckProcess}" type="text" name="checkProcess" class="layui-input">
    </div>


    <div class="bottom" style="position: fixed;bottom: 0">
        <div class="button-container">

            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="audit" lay-event="audit" lay-filter="audit">
                <i class="layui-icon layui-icon-ok"></i>
                鉴定评分
            </button>

        </div>
    </div>
</form>

<script type="text/javascript">
    function start() {
        if($("#proType").val() == "a"){
            $("#selectChild").hide();
        }
        //总结报告
        $("#summaryDisplay").show();
        var path = $("#uploadSummary").val();
        var index = path.lastIndexOf("/");
        var fileName = path.substring(index+1,path.length);
        $("#summaryDisplay").val(fileName);
        //项目最终成果
        $("#tt").show();
        var path2 = $("#proResUpload").val();
        var index2 = path2.lastIndexOf("/");
        var fileName2 = path2.substring(index2+1,path2.length);
        $("#tt").val(fileName2);
        //查重报告
        $("#dupDisplay").show();
        var path3 = $("#dupUpload").val();
        var index3 = path3.lastIndexOf("/");
        var fileName3 = path3.substring(index3+1,path3.length);
        $("#dupDisplay").val(fileName3);

        //免鉴模块
        if ($("input[name='other2']:checked").val() == 'y') {
            $("#avoidExpertItem").hide();
            $("#avoidReasonItem").show();
        } else if ($("input[name='other2']:checked").val() == 'n') {
            $("#avoidExpertItem").show();
            $("#avoidReasonItem").hide();
        }

        //审核按钮
        if ($("#checkProcess").val() == 0) {
            //隐藏审核通过按钮
            $("#audit").show();
        }
        if ($("#checkProcess").val() == 4) {
            //隐藏审核通过按钮
            $("#audit").hide();
        }
    }
</script>
<script>
    function closeSelf(){
        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
        parent.layui.table.reload("finishProject-table");
    }
</script>
<th:block th:include="include :: footer"/>
<script>
    var index1 = 0;
    var objList;
    $(function(){
        let MODULE_PATH = rootPath + "/FinishProjectController";
        $.ajax({
            url: MODULE_PATH + '/list2',
            dataType: 'json',
            contentType: 'application/x-www-form-urlencoded',
            type: 'get',
            success: function (result) {
                objList=result.val;
            }
        })
    })




    layui.use(['form', 'laydate', 'upload', 'jquery', 'table', 'layedit'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = rootPath + "/AuditFinishDanweiController";
        let table = layui.table;

        let FILE_PATH = rootPath + "/oss";
        let upload = layui.upload;
        let BucketName = '[[${BucketName}]]';
        var laydate = layui.laydate;
        var layedit = layui.layedit;

        //总结报告文件查看，调用后端接口
        $("#sum-view").click(function() {
            var path = $("#uploadSummary").val();
            var index = path.lastIndexOf("/");
            var fileName = path.substring(index+1,path.length);
            window.open("http://localhost:8080/static/pdf/web/viewer.html?file=http://localhost:8080/PDFViewController/filePdf/"+fileName);
        })

        //项目成果文件查看，调用后端接口
        $("#proRes-view").click(function() {
            var path = $("#proResUpload").val();
            var index = path.lastIndexOf("/");
            var fileName = path.substring(index+1,path.length);
            window.open("http://localhost:8080/static/pdf/web/viewer.html?file=http://localhost:8080/PDFViewController/filePdf/"+fileName);
        })

        //查重报告文件查看，调用后端接口
        $("#dup-view").click(function() {
            var path = $("#dupUpload").val();
            var index = path.lastIndexOf("/");
            var fileName = path.substring(index+1,path.length);
            window.open("http://localhost:8080/static/pdf/web/viewer.html?file=http://localhost:8080/PDFViewController/filePdf/"+fileName);
        })

        //项目类型的省级子项目显示与隐藏
        form.on('select(firstProType)', function (data) {
            // console.log($("#sheng").val());
            if ($("#proType option:selected").val() == "b") {
                $("#selectChild").show();
                form.render('select');
            } else {
                $("#selectChild").hide();
                form.render('select');//select是固定写法 不是选择器
            }
            form.render();
        });

        //绑定鉴定评分按钮
        $("#audit").click(function (data){
            var proId = $("#proId").val();
            // console.log(data);
            data.id = proId;
            layer.open({
                type: 2,
                title: '新增',
                area: ['1305px', '651px'],
                content: rootPath+"/FinishScoreController" + '/finishScore/' + data.id,
                success: function(layero, index) {
                    var body = layer.getChildFrame('body', index);//建立父子联系【核心语句】
                    var iframeWin = window[layero.find('iframe')[0]['name']];//【核心句】
                    // iframeWin.method();   //这句话的意思是可以通过ifarmeWin调用子页面的方法
                    var inputList = body.find('input');     //取得子页面中input输入框
                    //将父页项目ID传给子页面
                    body.find(inputList[0]).val(proId);
                }
            });
        });


        //获取选择项目radio的index
        form.on('radio(applyProjectList)', function (data) {
            // var proIndex = $("input[name='applyProjectList']:checked").val();
            var index=$("input[name='applyProjectList']").index($("input[name='applyProjectList']:checked"));
            $("#proName").val(objList[index].proName);
            if(objList[index].proType == "b"){
                $("#proType").val(objList[index].proType);
                // $("#proType").find("option[value='b']").attr("selected",true);
                $("#selectChild").show();
                $("#shengType").val(objList[index].proTypeChild);
                // $("#shengType").find("option[value= 'objList[index].proTypeChild' ]").attr("selected",true);
            }else if(objList[index].proType == "a"){
                $("#selectChild").hide();
                $("#proType").val("a");
                $("#shengType").val("a");
            }
            $("#proSubject").val(objList[index].proSubject);
            form.render();
            tableRender();
        });

        //配置申请免鉴理由的富文本编辑器
        var layeditAvoidReason = layedit.build('avoidReason',
            {
                tool: [
                    // 'strong' //加粗
                    // ,'italic' //斜体
                    // ,'underline' //下划线
                    // ,'del' //删除线
                    //
                    // ,'|' //分割线

                    'left' //左对齐
                    , 'center' //居中对齐
                    , 'right' //右对齐
                ]
            }); //建立编辑器

        //配置单位财务部门的富文本编辑器
        var layeditadviceInstFinance=layedit.build('adviceInstFinance',
            {
                tool: [
                    // 'strong' //加粗
                    // ,'italic' //斜体
                    // ,'underline' //下划线
                    // ,'del' //删除线
                    //
                    // ,'|' //分割线

                    ,'left' //左对齐
                    ,'center' //居中对齐
                    ,'right' //右对齐
                ]
            }); //建立编辑器

        //配置单位审计部门的富文本编辑器
        var layeditadviceInstCheck = layedit.build('adviceInstCheck',
            {
                tool: [
                    // 'strong' //加粗
                    // ,'italic' //斜体
                    // ,'underline' //下划线
                    // ,'del' //删除线
                    //
                    // ,'|' //分割线

                    ,'left' //左对齐
                    ,'center' //居中对齐
                    ,'right' //右对齐
                ]
            }); //建立编辑器

        //配置单位审核意见的富文本编辑器
        var layeditadviceInst=layedit.build('adviceInst',
            {
                tool: [
                    // 'strong' //加粗
                    // ,'italic' //斜体
                    // ,'underline' //下划线
                    // ,'del' //删除线
                    //
                    // ,'|' //分割线

                    ,'left' //左对齐
                    ,'center' //居中对齐
                    ,'right' //右对齐
                ]
            }); //建立编辑器

        //默认勾选不申请免于鉴定
        // $("#avoidExpertItem").show();
        // $("#avoidReasonItem").hide();

        //配置radio按钮的样式切换
        form.on("radio(applyAvoid)", function () {
            if (this.value == 'y') {
                $("#avoidExpertItem").hide();
                $("#avoidReasonItem").show();
            } else if (this.value == 'n') {
                $("#avoidExpertItem").show();
                $("#avoidReasonItem").hide();
            }
        });

//下载文件，调用后端接口
// 		function download(fileName,filePath){
// 			window.open("/downloadTwo?fileName="+encodeURI(fileName)+"&downUrl="+filePath);
// 			return ;
// 		}


        //监听页面滚动
        // window.onscroll = function() {
        // 	//为了保证兼容性，这里取两个值，哪个有值取哪一个
        // 	//scrollTop就是触发滚轮事件时滚轮的高度
        // 	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        // 	console.log("滚动距离" + scrollTop);
        // }


        // 滚动到指定位置
        // $("#top").click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});


        //总结报告成果简介（type=1）
        upload.render({
            elem: '#summarySelect-btn'
            , url: "/FileUploadController/edit/fileImp1/"+$("#proId").val()+'/'+1
            , auto: false
            //,multiple: true
            ,accept: 'file'
            , bindAction: '#summarySelect-upload'
            , choose: function (obj) {
                // var file = this.files = obj.pushFile();
                obj.preview(function (index, file, result) {
                    document.getElementById("summaryDisplay").style.display = "inline";
                    var xx = document.getElementById("summaryDisplay").value = file.name+'【'+(file.size / 1024 / 1024).toFixed(2) + 'MB'+'】';
                    // $("#demo1").attr('style','width:300px;heigth:400px');
                    // $("#demo1").attr('src',result);

                })

            }
            , done: function (res) {
                if(res.code==0){

                    return layer.msg('上传失败');
                }else {
                    return  layer.msg('上传成功');
                }
            }
        });

        //项目最终成果简介（type=2）
        upload.render({
            elem: '#resSelect-btn'
            , url: "/FileUploadController/edit/fileImp1/"+$("#proId").val()+'/'+2
            , auto: false
            //,multiple: true
            ,accept: 'file'
            , bindAction: '#resSelect-upload'
            , choose: function (obj) {
                // var file = this.files = obj.pushFile();
                obj.preview(function (index, file, result) {
                    document.getElementById("tt").style.display = "inline";
                    var xx = document.getElementById("tt").value = file.name+'【'+(file.size / 1024 / 1024).toFixed(2) + 'MB'+'】';
                    // $("#demo1").attr('style','width:300px;heigth:400px');
                    // $("#demo1").attr('src',result);

                })

            }
            , done: function (res) {
                if(res.code==0){

                    return layer.msg('上传失败');
                }else {
                    return  layer.msg('上传成功');
                }
            }
        });

        //查重报告（type=3）
        upload.render({
            elem: '#dupSelect-btn'
            , url: "/FileUploadController/edit/fileImp1/" + $("#proId").val() + '/' + 3
            , auto: false
            //,multiple: true
            , accept: 'file'
            , bindAction: '#dupSelect-upload'
            , choose: function (obj) {
                // var file = this.files = obj.pushFile();
                obj.preview(function (index, file, result) {
                    document.getElementById("dupDisplay").style.display = "inline";
                    var xx = document.getElementById("dupDisplay").value = file.name + '【' + (file.size / 1024 / 1024).toFixed(2) + 'MB' + '】';
                })
            }
            , done: function (res) {
                if (res.code == 0) {

                    return layer.msg('上传失败');
                } else {
                    return layer.msg('上传成功');
                }
            }
        });

        //同时绑定多个
        lay('.datetime-input').each(function () {
            laydate.render({
                elem: this
                , trigger: 'click'
                , type: 'date'
                , format: "yyyy-MM-dd HH:mm:ss"
            });
        });

        //同时绑定多个
        lay('.datetime-input').each(function () {
            laydate.render({
                elem: this
                , trigger: 'click'
                , type: 'date'
                , format: "yyyy-MM-dd HH:mm:ss"
            });
        });


        //课题参与者table字段
        let cols = [
            [
                {type: 'checkbox'},
                {title: '序号', type: 'numbers'},
                {title: '姓名', field: 'partName', align: 'center'},
                {title: '工作单位', field: 'partDept', align: 'center'},
                {title: '专业职称', field: 'partTitle', align: 'center'},
                {title: '承担任务', field: 'partTask', align: 'center'},
                {title: '操作', toolbar: '#applyParticipator-bar', align: 'center'}
            ]
        ]

        //参与者基本信息table表单列表
        form.render();
        table.render({
            elem: '#applyParticipator-table',
            url: rootPath + "/ApplyParticipatorController/" + 'listEdit/' + $("#proId").val()+'/'+$("#applyId").val(),      //此处跳转到ApplyParticipatorController
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#applyParticipator-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });


        //table图标事件绑定
        table.on('tool(applyParticipator-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(applyParticipator-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        //添加
        window.add = function () {
            var proId = $("#proId").val();
            var applyId = $("#applyId").val();
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['500px', '500px'],
                content: rootPath + "/ApplyParticipatorController/" + 'addFinish',
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);//建立父子联系【核心语句】
                    var iframeWin = window[layero.find('iframe')[0]['name']];//【核心句】
                    // console.log(body);
                    // iframeWin.method();   //这句话的意思是可以通过ifarmeWin调用子页面的方法
                    var inputList = body.find('input');     //取得子页面中input输入框
                    //将父页项目ID传给子页面
                    body.find(inputList[0]).val(proId);
                    body.find(inputList[1]).val(applyId);

                }
            });
        }

        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: rootPath + "/ApplyParticipatorController/" + 'editFinish/' + obj.data['id']
            });
        }

        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: rootPath + "/ApplyParticipatorController/" + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: rootPath + "/ApplyParticipatorController/" + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('applyParticipator-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //刷新按钮
        window.refresh = function () {
            table.reload('applyParticipator-table');
        }

        let cols2 = [
            [
                {type: 'checkbox'},


                {title: '成果名称', field: 'resName', align: 'center'},

                {title: '成果形式', field: 'resType', align: 'center'},

                {title: '作者', field: 'resAuthor', align: 'center'},

                {title: '出版社', field: 'publishCompany', align: 'center'},

                {
                    title: '出版时间', field: 'publishTime', align: 'center',
                    templet: "<div>{{layui.util.toDateString(d.updateTime, 'yyyy-MM-dd')}}</div>"
                },

                {title: '操作', toolbar: '#finishSatgeResult-bar', align: 'center'}
            ]
        ]

        //阶段性成果table表单列表
        table.render({
            elem: '#finishSatgeResult-table',
            url: rootPath + "/FinishSatgeResultController/" + 'list/' + $("#proId").val(),
            page: true,
            method: 'get',
            cols: cols2,
            skin: 'line',
            toolbar: '#finishSatgeResult-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });

        //table图标事件绑定
        table.on('tool(finishSatgeResult-table)', function (obj) {
            if (obj.event === 'remove2') {
                window.remove2(obj);
            } else if (obj.event === 'edit2') {
                window.edit2(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(finishSatgeResult-table)', function (obj) {
            if (obj.event === 'add2') {
                window.add2();
            } else if (obj.event === 'refresh2') {
                window.refresh2();
            } else if (obj.event === 'batchRemove2') {
                window.batchRemove2(obj);
            }
        });

        //添加
        window.add2 = function () {
            var proId = $("#proId").val();
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['500px', '500px'],
                content: rootPath + "/FinishSatgeResultController/" + 'add',
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);//建立父子联系【核心语句】
                    var iframeWin = window[layero.find('iframe')[0]['name']];//【核心句】
                    // console.log(body);
                    // iframeWin.method();   //这句话的意思是可以通过ifarmeWin调用子页面的方法
                    var inputList = body.find('input');     //取得子页面中input输入框
                    //将父页项目ID传给子页面
                    body.find(inputList[0]).val(proId);
                }

            });
        }
        //修改
        window.edit2 = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: rootPath + "/FinishSatgeResultController/" + 'edit/' + obj.data['id']
            });
        }
        //删除
        window.remove2 = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: rootPath + "/FinishSatgeResultController/" + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove2 = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: rootPath + "/FinishSatgeResultController/" + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('finishSatgeResult-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //刷新按钮
        window.refresh2 = function () {
            table.reload('finishSatgeResult-table');
        }

        //保存
        form.on('submit(save)', function (data) {
            //单位状态为待提交
            data.field.deptPass = 5;

            //审核意见富文本
            data.field.adviceInstFinance = layedit.getContent(layeditadviceInstFinance);
            data.field.adviceInstCheck = layedit.getContent(layeditadviceInstCheck);
            data.field.adviceInst = layedit.getContent(layeditadviceInst);

            let loader = layer.load();

            $.ajax({
                url: MODULE_PATH + '/edit',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("finishProject-table");
                            layer.close(loader);
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                        layer.close(loader);
                    }
                }
            })
            return false;
        });

        //审核通过
        form.on('submit(FinishProject-pass)', function (data) {

            data.field.adviceInstFinance = layedit.getContent(layeditadviceInstFinance);
            data.field.adviceInstCheck = layedit.getContent(layeditadviceInstCheck);
            data.field.adviceInst = layedit.getContent(layeditadviceInst);
            //单位审核通过
            data.field.deptPass = 1;
            //社科联审核状态为待审核
            data.field.sklPass = 0;

            layer.confirm('确定要提交信息，提交后将无法更改', {icon: 3, title: '提示'}, function (index) {
                let loader = layer.load();
                $.ajax({
                    url: MODULE_PATH + '/edit',
                    data: data.field,
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                parent.layui.table.reload("finishProject-table");
                                layer.close(loader);
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                            layer.close(loader);
                        }
                    }
                })
            })
            return false;
        });

        //审核不通过
        form.on('submit(FinishProject-noPass)', function (data) {

            data.field.adviceInstFinance = layedit.getContent(layeditadviceInstFinance);
            data.field.adviceInstCheck = layedit.getContent(layeditadviceInstCheck);
            data.field.adviceInst = layedit.getContent(layeditadviceInst);
            //单位审核不通过
            data.field.deptPass = 2;
            //项目状态为审核不通过
            data.field.proState = 2;
            layer.confirm('确定要提交信息，提交后将无法更改', {icon: 3, title: '提示'}, function (index) {
                let loader = layer.load();
                $.ajax({
                    url: MODULE_PATH + '/edit',
                    data: data.field,
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                parent.layui.table.reload("finishProject-table");
                                layer.close(loader);
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                            layer.close(loader);
                        }
                    }
                })
            })
            return false;
        });



        function tableRender() {
            var id = $("input[name='applyProjectList']:checked").val();

            if (!id) {
                return;
            }
            table.render({
                elem: '#applyParticipator-table',
                url: rootPath + "/ApplyParticipatorController/" + 'listFinish/' + $("#proId").val() + '/' + id,      //此处跳转到ApplyParticipatorController
                page: true,
                method: 'get',
                cols: cols,
                skin: 'line',
                toolbar: '#applyParticipator-toolbar',
                defaultToolbar: [{
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter']
            });
        }
    })
</script>
</body>
</html>
